<?php
$idUser=$_SESSION['iduser'];
if(count($_POST)>0)
{
	
	$email=$_POST['email'];
	$oldpass=$_POST['oldpass'];
      
      
      
	$newpass=$_POST['newpass'];
	$repass=$_POST['repass'];
      if($newpass == $repass){
          $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
    // Create salted password (Careful not to over season)
    $password = hash('sha512', $newpass.$random_salt);
    $sql="update user set
	email='$email',
	pass='$password',
      salt='$random_salt'    
	where id='$idUser'";
	mysqli_query($conn,$sql);
    //echo $sql;
	echo "Update successed!";
      writeLog($conn, $user_id, "Change Profile");
      }
	
}
$sql='select * from `user` where `id`='.$idUser;
$rs=mysqli_query($conn,$sql);
$r=mysqli_fetch_assoc($rs);

?>


<div id="stylized" class="myform">

    <form id="form" name="form" method="post">

        <h1>Edit Profile</h1>
        <p>You can update your email address or change your password</p>

       <label>Email
            <span class="small">Add a valid address</span>
        </label>
        <input type="text" name="email"  value="<?php echo $r['email']?>" />

         <label>Password Old
            <span class="small">Min. size 6 chars</span>
        </label>
         <input type="password" name="oldpass"  />

        <label>New Password
            <span class="small">Min. size 6 chars</span>
        </label>
        <input type="password" name="newpass"  />

        <label>Retype Password
            <span class="small">Min. size 6 chars</span>
        </label>
        <input type="password" name="repass"/>

        <button type="submit">Sign-up</button>
        <div class="spacer"></div>

    </form>
</div>
